//
//  FPOrderDetailVC.m
//  ForestPack
//
//  Created by jimmy on 2018/7/22.
//  Copyright © 2018年 郑洲. All rights reserved.
//

#import "FPOrderDetailVC.h"
#import "OrderDetailFirstCell.h"

@interface FPOrderDetailVC ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong)  BaseTableView  * tableView;
@property (nonatomic,strong)  NSDictionary   * dict;

@end

@implementation FPOrderDetailVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setTitle:@"订单详情"];
    [self setTableViewUI];
    [self getData];
}

- (void)getData {
    [HttpManager postHttpRequestByPost:[NSString stringWithFormat:@"%@app/design_order_detail",REQUESTHEADER] andParameter:@{@"token":[FPLoginAndRegisterTools getToken],@"id":_Id} success:^(id successResponse) {
        NSString *status = [NSString stringWithFormat:@"%@",successResponse[@"status"]];
        if ([status isEqualToString:@"1"]) {
            self.dict = successResponse[@"data"];
            [self.tableView reloadData];
        }
    } andFailure:^(id failureResponse) {
        [HttpManager showFail];
    }];
}

- (void)acceptOrder {
    
}

- (void)setTableViewUI
{
    self.tableView = [[BaseTableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - NAVIGATION_BAR_HEIGHT) style:UITableViewStyleGrouped];
    self.tableView.estimatedRowHeight = 0;
    self.tableView.estimatedSectionHeaderHeight = 0;
    self.tableView.estimatedSectionFooterHeight = 0;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
    
}

#pragma mark - tableView的delegate和datasource
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 2) {
        return 7;
    }
    return 1;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        return 108;
    }else if (indexPath.section == 1){
        return 130;
    }else{
        return 44;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.01;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc] init];
    
    return view;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    if (section == 2) {
        return 130;
    }
    return 10;
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    if (section == 2) {
        //这里需要加判断，判断是否需要显示接单按钮
        UIView *view = [[UIView alloc] init];
        OperateButton *button = [[OperateButton alloc] init];
        button.frame = CGRectMake(13, 30, SCREEN_WIDTH - 26, 44);
        [button setTitle:@"接单" forState:UIControlStateNormal];
        [button addTarget:self action:@selector(acceptOrder) forControlEvents:UIControlEventTouchUpInside];
        [view addSubview:button];
        
        return view;
    }else{
        UIView *view = [[UIView alloc] init];
        return view;
    }
    
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSArray *leftArr = @[@"产品:",@"堆叠层数:",@"产品重量:",@"参考模板:",@"箱型:",@"设计师:",@"价格:"];
    NSArray *rightArr = @[@"水印",@"2层",@"10kg",@"参考模板",@"粘箱",@"设计师007",@"￥9999"];
    
    if (indexPath.section == 0) {
        OrderDetailFirstCell *cell = [OrderDetailFirstCell cellWithTableView:tableView indexPath:indexPath];
        if (_dict) {
            [cell initWithDict:_dict];
        }
        return cell;
    }else if (indexPath.section == 1){
        OrderInfoCell *cell = [OrderInfoCell cellWithTableView:tableView indexPath:indexPath];
        if (_dict) {
            [cell initWithDict:_dict];
        }
        return cell;
    }else{
        OrderDetailThirdCell *cell = [OrderDetailThirdCell cellWithTableView:tableView indexPath:indexPath withTitle:leftArr[indexPath.row] withDetailInfo:rightArr[indexPath.row]];
        return cell;
    }
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:false];
}

@end
